package test.com.sky.designPattern.statePattern;

import com.sky.JULLog.MyLogger;

import java.util.logging.Logger;

/**
 * 定义电梯类
 */
public class Lift {

    private Logger log = MyLogger.getLogger(Lift.class);


    //定义出电梯的所有状态
    private LiftState openingState;
    private LiftState closingState;
    private LiftState runningState;
    private LiftState stoppingState;

    // 定义当前电梯状态
    private LiftState currentState;


    /**
     * 构造方法
     */
    Lift() {
        openingState = new OpeningState(this);
        closingState = new ClosingState(this);
        runningState = new RunningState(this);
        stoppingState = new StoppingState(this);
        log.info("lift 电梯已创建; ");
    }

    /**
     * 执行开门动作
     */
    void open() {
        currentState.open();
    }

    /**
     * 执行关门动作
     */
    void close() {
        currentState.close();
    }

    /**
     * 执行运行动作
     */
    public void run() {
        currentState.run();
    }

    /**
     * 执行停止动作
     */
    void stop() {
        currentState.stop();
    }

    // ##################设置当前电梯状态#####################

    /**
     * 设置当前电梯状态
     *
     * @param state 电梯状态
     */
    void setState(LiftState state) {
        log.warning("当前状态设置成为:" + state.getClass().getName());
        this.currentState = state;
    }

    // ###################获取电梯的全部状态####################

    LiftState getOpeningState() {
        return openingState;
    }

    LiftState getClosingState() {
        return closingState;
    }

    LiftState getRunningState() {
        return runningState;
    }

    LiftState getStoppingState() {
        return stoppingState;
    }

}
